<?php
/**
 * User: jack<linjue@wilead.com>
 * Create At: 14/11/12
 */

namespace Wilead\IArtistBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use JPush\Model as M;
use JPush\JPushClient;

class JPushController extends Controller
{
    public function batchPushAction(Request $request)
    {
        $error = '';
        if ($request->isMethod('post')) {
            $content = $request->request->get('content');
            if (strlen($content) > 0) {
                $client = new JPushClient('13fab03e3c235eba3f7c4205', 'c38c1917e44634808f0f8dc4');
                $client
                    ->push()
                    ->setPlatform(M\all)
                    ->setAudience(M\all)
                    ->setNotification(M\notification($content))
                    ->send();
                $error = '发送成功';
            } else
                $error = '内容不能为空';
        }

        return $this->render('WileadIArtistBundle:JPush:form.html.twig', array(
            'error' => $error
        ));
    }
}